Triple-Arm Crane
Memory limit: 32 MB
A triple-arm crane places containers on railway wagons. The wagons are numbered in order
. On each wagon at most one container can be put. In one move the crane gets three containers from a storehouse and places them on wagons with numbers
,
and
, or on wagons with numbers
,
and
(for some constants
). The crane has to be programmed in such way, that it loads with containers the first n wagons of the train (the train has n+p+q wagons). The program consists of sequence of instructions. Each instruction describes one move of the crane. Such instruction forms a (x, y, z) triple, where
, and determines numbers of wagons, on which the crane has to place the containers. The program is correct if after its execution there is exactly one container on each of the first n wagons of the train.
Task
Write a program which:
- reads a description of the crane (numbers
and
) and a number of wagons to be loaded (
) from the standard input,
- generates a correct program for the crane,
- writes it to the standard output.
Input
The first and the only line of the standard input contains exactly three positive integers separated by single spaces. These are adequately numbers
and
describing parameters of the crane and number
, being the number of the first wagons of the train to be loaded. These numbers satisfy inequalities
,
.
Output
The first line of the standard output should consist of exactly one integer
being the number of instructions in the program generated. Each of the next
lines should consist of exactly three integers
,
,
separated by single spaces,
,
,
belongs to
,
. These are the numbers of the wagons, on which the crane has to put containers in a consecutive move.
Example
For the input data:
2 3 10
the correct result is:
4
1 3 6
2 4 7
5 8 10
9 11 14
Task author: Wojciech Rytter.